//
//  EmoticonPackage.swift
//  微博分支表情键盘
//
//  Created by JJ on 15/9/12.
//  Copyright © 2015年 JJ. All rights reserved.
//

import UIKit

class EmoticonPackage: NSObject {

    var id:String?
    
    var group_name_cn:String?
    
    lazy var emoticons = [Emoticon]()
    
    init(dic:[String:AnyObject]){
        super.init()
        
        id = dic["id"] as? String
        
        group_name_cn=dic["group_name_cn"] as? String

        var index=0
        
        if let array = dic["emoticons"] as?[[String:String]]{
            
            for var d in array{
                
                if let pngPath = d["png"]{
                    
                    d["png"] = id! + "/" + pngPath
                    
                }
                emoticons.append(Emoticon(dic:d))
                
                 index++
                if index==20{
                    
                    emoticons.append(Emoticon(isRemove: true))
                    index=0
                }
            }
        }
        appendBlankEmoticon()
    }
    
    private func appendBlankEmoticon(){
        
        let count=emoticons.count % 21
        
        print(count)
        
        if count==0 && count > 0{
            return
        }
        for _ in count..<20{
        
            emoticons.append(Emoticon(isEmpty: true))
        }
        emoticons.append(Emoticon(isRemove: true))
        
    }
    override var description:String{
        let keys=["id","group_name_cn","emoticons"]
        
        return dictionaryWithValuesForKeys(keys).description
    }
    
}
